import qs from 'qs'
// import axios from 'axios'

const WX_APPID = process.env.VUE_APP_WX_APPID
const WX_AUTH_URL = 'https://open.weixin.qq.com/connect/oauth2/authorize'
const WX_SUFFIX = '#wechat_redirect'
const WX_SCOPE = 'snsapi_userinfo' // 非静默授权，snsapi_base为静默授权，只获取openID
const WX_STATE = 'STATE'

export const wxAuth = () => {
  const prefixed = qs.parse(window.location.search, { ignoreQueryPrefix: true })
  console.log(prefixed.webUrl)
  if (prefixed.code === undefined) {
    const authParam = {
      appid: WX_APPID,
      redirect_uri: window.location.href,
      response_type: 'code',
      scope: WX_SCOPE,
      state: WX_STATE
    }
    window.location.href = `${WX_AUTH_URL}?${qs.stringify(authParam)}${WX_SUFFIX}`
  }
}
